package org.software.views;


import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

public class LoginFrame extends javax.swing.JFrame {

    private JLabel message;
    private JTextField idField;
    private JPasswordField pwdField;

    public LoginFrame() {
        setTitle("登陆系统");
        setSize(600, 400);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLayout(new FlowLayout(FlowLayout.CENTER));
        idField = new JTextField(10);
        pwdField = new JPasswordField(10);
        JButton loginButton = new JButton("登陆");
        JButton cancelButton = new JButton("取消");
        message = new JLabel();

        JPanel panel = new JPanel();
        panel.add(idField);
        panel.add(pwdField);
        panel.add(loginButton);
        panel.add(cancelButton);
        panel.add(message);
        add(panel);
        setLayout(new FlowLayout(FlowLayout.CENTER,30,10));
        JPanel textPanel = new JPanel();
        JPanel psdPanel = new JPanel();
        JPanel buttonPanel = new JPanel();
        textPanel.add(new JLabel("用户名"));
        textPanel.add(idField);
        psdPanel.add(new JLabel("密  码"));
        psdPanel.add(pwdField);
        buttonPanel.add(loginButton);
        buttonPanel.add(cancelButton);
        buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER,30,20));
        panel.add(textPanel);
        panel.add(psdPanel);
        panel.add(buttonPanel);
        add(panel);



        loginButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String id = idField.getText();
                String password = new String(pwdField.getPassword());

                if (id.equals("1001") && password.equals("123456")) {
                    dispose();
                    new  MenuFrame();
                }
                else{
                    message.setText("登陆失败，用户名或密码错误！");
                }
            }
        });

        cancelButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dispose();
            }
        });

        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setSize(600,400);

        setVisible(true);


    }

    public  static  void main(String[] args){
        new LoginFrame();
    }

}

